package com.ncu.web.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ncu.web.entry.Contacts;
import com.ncu.web.entry.ReturnData;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface ContactsMapper extends BaseMapper<Contacts> {

    @Select("select * from contacts where id=#{id}")
    Contacts selectContactsById(int id);

    @Select("select * from contacts where contacts.email=#{email}")
    Contacts selectByEmail(String email);

    @Select("select * from contacts where contacts.phone=#{phone}")
    Contacts selectByPhone(Long phone);

    @Select("select * from student,contacts where contacts.id=#{id} and student.contacts=contacts.id  and student.permission = 1")
    ReturnData selectById(String id);


    @Select("select * from student,contacts where student.name=#{name} and student.contacts=contacts.id  and student.permission = 1")
    List<ReturnData> selectByName(String name);


    @Select("select * from student,contacts where student.contacts=contacts.id and student.permission = 1")
    List<ReturnData> selectAll();

    @Select("SELECT majority.name AS name, COUNT(*) AS value FROM contacts LEFT JOIN majority ON contacts.majority = majority.id GROUP BY contacts.majority")
    List<Map<String, Object>> countByMajority();

    @Select("SELECT city as name, COUNT(*) AS value FROM contacts GROUP BY city")
    List<Map<String, Object>> countByCity();



}
